package com.xiaoxu.bbs.common;


import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class BbsMetaObjectHandler implements MetaObjectHandler {
    /**
     * 执行插入操作时，自动填充
     *
     */
    @Override
    public void insertFill(MetaObject metaObject) {
//        ThreadLocal threadLocal = new ThreadLocal();
        metaObject.setValue("createTime", LocalDateTime.now());
        metaObject.setValue("updateTime", LocalDateTime.now());
//        metaObject.setValue("createUser", BaseContext.getCurrentId());
//        metaObject.setValue("updateUser", BaseContext.getCurrentId());
    }

    /**
     * 执行更新操作时，自动填充
     *
     */
    @Override
    public void updateFill(MetaObject metaObject) {
//        metaObject.setValue("updateUser", BaseContext.getCurrentId());
        metaObject.setValue("updateTime", LocalDateTime.now());
    }
}
